package com.sanley.piss.web.controller;

import com.sanley.piss.mapper.OrganizationMapper;
import com.sanley.piss.model.exceptionUtil.json.JsonResult;
import com.sanley.piss.model.po.Organization;
import com.sanley.piss.web.service.mapper.IOrganizationService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;
import java.util.Set;

/**
 * Create By  on 2021/3/22.
 * @author 张凯大天才
 */
@Api(value = "组织表controller",tags = "组织表操作接口")
@RestController
@RequestMapping("organizetion")
public class OrganizationController {

    @Autowired
    private IOrganizationService service;

    @Autowired
    private OrganizationMapper organizationMapper;

    @ApiOperation(value ="插入一条记录" )
    @RequestMapping(value = "/insert",method = RequestMethod.PUT)
    public JsonResult<Object> insert(@Valid Organization organization){
        service.insert(organization);
        return JsonResult.success();
    }

    @ApiOperation(value ="根据ID删除多条角色")
    @RequestMapping(value = "/delete/{ids}",method = RequestMethod.DELETE)
    public JsonResult<Object> delete(@PathVariable("ids") Integer[] ids){
        service.removeByIds(ids);
        return JsonResult.success();
    }

    @ApiOperation(value ="根据ID修改一条数据")
    @RequestMapping(value = "/update",method = RequestMethod.POST)
    public JsonResult update(@Valid Organization organization){
        service.updateById(organization);
        return JsonResult.success();
    }

    @ApiOperation(value ="根据ID查询一条信息")
    @RequestMapping(value = "/selectById",method = RequestMethod.GET)
    public JsonResult<Organization> selectById(Integer id){
        return JsonResult.success(service.selectById(id));
    }

    @ApiOperation(value ="查询组织名")
    @RequestMapping(value = "/selectIdOrName",method = RequestMethod.GET)
    public JsonResult<Set<String>> selectIdOrName(){
        return JsonResult.success(organizationMapper.selectOrgIdAndName());
    }


}
